﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CDV.MC.MatrixDriver.WebApp.Filter
{
    public class LoginFilter : ActionFilterAttribute 
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var isLogin = context.HttpContext.Session.GetInt32("IsLogin");

            if (!isLogin.HasValue || isLogin.Value == 0)
            {
                context.Result = new RedirectToActionResult("Login", "Matrix", null);
                return;
            }

            base.OnActionExecuting(context);
        }
    }
}
